package com.ys.controller.api.sys;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.ys.dto.DtreeSqlDto;
import com.ys.entity.sys.YsButton;
import com.ys.service.sys.CommonApiService;
import com.ys.service.sys.YsButtonService;
import com.ys.vo.LayuiTableVoJA;
import com.ys.vo.R;

@Controller
@RequestMapping("/api/inter/ysButton")
public class ApiInterYsButtonController {
	
//	private static final Logger logger = Logger.getLogger(ApiAdminLoginController.class);
	
	@Autowired
	private CommonApiService<YsButton> commonApiService;
	@Autowired
	private YsButtonService ysButtonService;

//	@RequiresPermissions("system:ysButton:view")
	@RequestMapping("/search")
    @ResponseBody
	public LayuiTableVoJA search(Model model, HttpServletRequest request, HttpServletResponse response,
			@ModelAttribute YsButton cond
			){
		
		cond.setOrderby("A.MenuId asc, A.SortNo asc");
		
		return commonApiService.searchLay(cond);
	}
	
	@RequestMapping("/dtree")
    @ResponseBody
	public DtreeSqlDto dtree(Model model, HttpServletRequest request, HttpServletResponse response
			){
		return ysButtonService.dtree();
	}
	
	/**
	 * 新增
	 */
	@PostMapping("/add")
    @ResponseBody
	public R add(Model model, HttpServletRequest request, HttpServletResponse response,
			Long menuId,
			Integer type,
			Integer styleType,
			Integer sortNo,
			String event,
			String name,
			String icon,
			String nameShiroAuth){
		
		return ysButtonService.add(menuId, type, styleType, sortNo, event, name, icon, nameShiroAuth);
	}
	
	/**
	 * 编辑
	 */
	@PostMapping("/edit")
    @ResponseBody
	public R edit(Model model, HttpServletRequest request, HttpServletResponse response,
			Long id,
			Integer type,
			Integer styleType,
			String name,
			String event,
			String icon,
			String nameShiroAuth){
		
		return ysButtonService.edit(id, type, styleType, name, event, icon, nameShiroAuth);
	}
	
	/*
	 * 彻底删除
	 */
	@PostMapping("/deleteTrue")
	@ResponseBody
	public R deleteTrue(HttpServletRequest request, HttpServletResponse response,
			Long id) {
		return ysButtonService.deleteTrue(id);
	}
	
}
